<?php
$screen = Blyn::app()->getUIManager()->getCurrentScreen();
$url = $control->getAjaxLinkUrl('AddCard', NULL, array(
    'cooker' => 'BAMemberCard@addCard',
    'memberCardId' => $cardId,
        ));
$updateId = $control->getAjaxContainerId();
?>

<?php
$form = $this->beginWidget('CActiveForm', array(
    "id" => "addCardForm",
    'enableAjaxValidation' => FALSE,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
        ));
?>
<script type="text/javascript">
// this script for collecting the form data and pass to the controller action and doing the on success validations
    function saveCardRequest() {
        var formData = new FormData($("#addCardForm")[0]);
        $.ajax({
            url: '<?php echo $url; ?>',
            type: 'POST',
            data: formData,
            //datatype: 'json',
            // async: false,
            beforeSend: function() {
                $("#ajax-loaderdiv").show();
            },
            success: function(html) {
                // on success do some validation or refresh the content div to display the uploaded images 
                jQuery("#<?php echo $updateId; ?>").html(html);
            },
            complete: function() {
                $("#ajax-loaderdiv").hide();
            },
            error: function(data) {
                alert("There may a error on uploading. Try again later");
            },
            cache: false,
            contentType: false,
            processData: false
        });

        return false;
    }
</script>
<legend><h4><?php
        echo $control->getAjaxLink(array('name' => '功能列表', 'id' => 'showEventList'), array(
            'cooker' => 'BAEvent@showEventList'
        ));
        ?>\
        <?php
        echo $control->getAjaxLink(array('name' => '会员卡类型', 'id' => 'ShowCardTypeList'), array(
            'cooker' => 'BAMemberCard@showCardTypeList'
        ));
        ?>\
        <?php
        $mCardCooker = new BAMemberCardCooker();
        $cardTypeAlias = $mCardCooker->getCurrentCardType()->getValue();
        echo $control->getAjaxLink(array('name' => $cardTypeAlias, 'id' => 'showCardList'), array(
            'cooker' => 'BAMemberCard@showCardList'
        ));
        ?>\
        <?php
        if ($cardId == NULL) {
            $title = '新增';
        }
        if (is_numeric($cardId) && $cardId > 0)
            $title = '修改';
        echo $title;
        ?>
    </h4></legend>
<div class="tabbable tabs-right" style="margin-top: 15px;"> <!-- Only required for left/right tabs -->
    <ul class="nav nav-tabs" style="margin-bottom: 15px">
        <li class="active"><a href="#tab1" data-toggle="tab"><?php echo '基本信息'; ?></a></li>    
        <li class=""><a href="#tab2" data-toggle="tab"><?php echo '添加属性'; ?></a></li>    
    </ul>
    <div class="tab-content">
        <div class="tab-pane active" id="tab1" style="min-height: 180px">                
            <?php
            //增加默认字段
            //$typeList = array('0' => '请选择', 'promotionCard' => '促销卡', 'discountCard' => '打折卡');
            $genderList = array('0' => '请选择', 'mister' => '先生', 'lady' => '女士', 'boy' => '男孩', 'girl' => '女孩');
            ?>
            <table class="table table-hover">
                <colgroup>
                    <col class="span1">
                    <col class="span7">
                </colgroup>
                <thead>
                    <tr>
                        <th><?php echo '属性'; ?></th>
                        <th><?php echo '内容'; ?></th>
                    </tr>
                </thead>
                <tbody>
                    <tr><td> <?php echo '实体卡号'; ?> </td>
                        <td>
                            <?php
                            echo $form->textField($model, $fixedCardIdField, array('placeholder' => '实体卡号' . '...', 'required' => true));
                            ?>
                        </td>
                    </tr>
                    <tr><td> <?php echo '用户手机'; ?> </td>
                        <td>
                            <?php
                            echo $form->textField($model, $mobileField, array('placeholder' => '手机号' . '...', 'required' => true));
                            ?>
                        </td>
                    </tr> 
                    <tr><td> <?php echo '尊姓'; ?> </td>
                        <td>
                            <?php
                            //CHtml::activeDropDownList($model, $title, $genderList)
                            echo $form->dropDownList($model, $genderField, $genderList, array('class' => 'span2'));
                            echo $form->textField($model, $familyNameField, array('placeholder' => '姓氏' . '...', 'required' => true));
                            ?>
                        </td>
                    </tr>
                    <tr><td> <?php echo '大名'; ?> </td>
                        <td>
                            <?php
                            echo $form->textField($model, $surNameField, array('placeholder' => '大名' . '...', 'required' => true));
                            ?>
                        </td>
                    </tr>
                    <tr><td> <?php echo '生日'; ?> </td>
                        <td>
                            <?php
                            echo $form->textField($model, $birthField, array('placeholder' => '生日' . '...', 'required' => true));
                            ?>
                        </td>
                    </tr>
                    <tr><td> <?php echo '有效期至'; ?> </td>
                        <td>
                            <?php
                            echo $form->textField($model, $expireTimeField, array('placeholder' => '默认为永远有效' . '...', 'required' => true));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td> <?php echo '说明'; ?>  </td>                    
                        <td>
                            <?php
                            echo $form->textArea($model, $descriptionField, array('placeholder' => '说明' . '...'));
                            ?>
                    </tr>
                </tbody>
            </table>
        </div>  
        <div class="tab-pane" id="tab2" style="min-height: 180px">                
            <?php
            if (isset($card) && $card != NULL) {
                $control1 = new BUIAttribute('showMemberCardAttribute');

                $control1->prepareAttributeView('memberCardAttribute', $card, 'add_card');
                $control1->render();
            }
            ?>  
        </div>
    </div>
</div>
<?php
$this->endWidget();
?>
<button class="btn" onclick="javascript:saveCardRequest()"><?php echo '保存' ?></button>